﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using ExFlash.Actions;

namespace ExFlash.Records
{
    [TypeConverter(typeof(ExpandableObjectConverter))]
    public class ClipActionRecord : ISwfSerializable
    {
        private readonly int _swfVersion;
        
        public ClipEventFlags Flags
        {
            get;
            private set;
        }

        public UInt32 ActionRecordSize
        {
            get;
            private set;
        }

        public Byte KeyCode
        {
            get;
            private set;
        }

        public List<ActionRecord> Actions
        {
            get;
            private set;
        }

        public ClipActionRecord(int version)
        {
            _swfVersion = version;
        }

        #region ISwfSerializable Members

        public void SwfDeserialize(BinaryBitReader reader)
        {
            Flags = new ClipEventFlags(_swfVersion);
            Flags.SwfDeserialize(reader);

            ActionRecordSize = reader.ReadUInt32();

            if (Flags.ClipEventKeyPress)
            {
                KeyCode = reader.ReadByte();

                Actions = ActionAssistant.GetActionsByLength(reader, ActionRecordSize - 1, _swfVersion);
            }
            else
            {
                Actions = ActionAssistant.GetActionsByLength(reader, ActionRecordSize, _swfVersion);
            }
        }

        public void SwfSerialize(byte[] arr, ref int offset)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
